// page_two/yjx/yjx.js
let app = getApp()
let yuming = app.globalData.yuming
var shuzong = []
var shu = []
const request = require('../../config/request');
Page({
  ...request,
  /**
   * 页面的初始数据
   */
  data: {
    yuming: yuming,
    heights: "",
    title: '',
    huan: ['已回复', '未回复'],
    currtab: 0,
    addpub: '',
    sblist: [],
    id: '',
    page: 1
  },
  // 查看更多
  lookmore() {
    shuzong = this.data.sblist
    this.setData({
      page: (this.data.page) + 1
    })
    this.xdxdjk()
  },
  // 接口
  xdxdjk() {
    var that = this
    var u = '';
    if (that.data.id == 6) {
      u = 'shop/shopSelectCleanlog'
    }
    if (that.data.id == 7) {
      u = 'shop/shopSelectGreaselog'
    }
    if (that.data.id == 8) {
      u = 'Shop/shopSelectFoodquality'
    }
    if (that.data.id == 9) {
      u = 'shop/shopSelectPestlog'
    }
    if (that.data.id == 10) {
      u = 'shop/shopSelectitiveLog'
    }
    this.myRequest(yuming + u, {
      shopId: wx.getStorageSync('shopId'),
      page: that.data.page
    }, "POST").then(res => {
      shu = res.data.data
      if (that.data.page != 1) {
        if (shu.length == 0) {
          wx.showToast({
            title: '没有更多数据了~',
            icon: "none"
          })
          that.setData({
            sblist: []
          })
        }
      }
      that.setData({
        // sblist: shuzong.concat(shu)
      })
    })
  },
  // 删除
  shan(e) {
    var id = e.currentTarget.dataset.id
    var that = this
    wx.showModal({
      title: '您确定要删除吗？',
      cancelText: '取消',
      confirmText: '确定',
      success: function (res) {
        if (res.confirm) {
          console.log("确定")
          that.dele(id)
        } else {
          console.log("取消")
        }
      }
    })
  },
  // 删除接口
  dele(id) {
    let that = this
    var u = '';
    if (that.data.id == 6) {
      u = 'shop/shopDelCleanlog'
    }
    if (that.data.id == 7) {
      u = 'shop/shopDelGreaselog'
    }
    if (that.data.id == 8) {
      u = 'Shop/shopDelFoodquality'
    }
    if (that.data.id == 9) {
      u = 'shop/shopDelPestlog'
    }
    if (that.data.id == 10) {
      u = 'shop/shopDelitiveLog'
    }
    this.myRequest(yuming + u, {
      shopId: wx.getStorageSync('shopId'),
      id: id
    }, "POST").then(res => {
      wx.showToast({
        title: res.data.msg,
        icon: 'none'
      })
      if (res.data.code == 200) {
        that.xdxdjk()
      }
    })
  },
  // 知识产权 点击放大
  fangda(e) {
    var img = e.currentTarget.dataset.img
    var list = e.currentTarget.dataset.list
    var arr = []
    for (let i in list) {
      arr.push(list[i]); //属性
    }
    wx.previewImage({
      current: img,
      urls: arr
    })
  },
  // tab切换
  qies(e) {
    var index = e.currentTarget.dataset.currtab
    this.setData({
      currtab: index,
      page: 1
    })
  },
  backs() {
    wx.navigateBack({
      delta: 0
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5,
      title: options.title,
      id: options.id,
      cid: options.cid
    })
  },
  // 添加
  jias() {
    wx.navigateTo({
      url: '/page_two/addpublics/addpublics?title=' + this.data.addpub + "&id=" + this.data.id + "&cid=" + this.data.cid,
    })
  },
  // 制度
  zhidu() {
    let that = this
    this.myRequest(yuming + 'shop/ShopFindCartInfo', {
      shopId: wx.getStorageSync('shopId'),
      cid: that.data.cid
    }, "POST").then(res => {
      that.setData({
        xq: res.data.data,
        content: res.data.data.colExplain.replace(/(\<img|\<p)/gi, function ($0, $1) {
          return {
            "<img": '<img style="width:100%;height:auto;display:block;" ',
            "<p": '<p style="text-indent: 2em;" ',
            "<article": "<div",
            "</article": "</div",
            "<header": "<div",
            "</header": "</div"
          } [$1];
        })
      })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.xdxdjk()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})